package com.sky.controller.admin;

import com.sky.anno.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api("菜品控制类")
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    private DishService dishService;
    /**
     * 菜品分页查询接口
     */
    @GetMapping("/page")
    @ApiOperation("菜品分页查询接口")
    public Result<PageResult> getDishByPage(DishPageQueryDTO dishPageQueryDTO){
        log.info("菜品分页查询dishPageQueryDTO:{}",dishPageQueryDTO);
        PageResult pr = dishService.getDishByPage(dishPageQueryDTO);
        return Result.success(pr);
    }
    /**
     * 新增菜品接口
     */
    @PostMapping
    @ApiOperation("新增菜品接口")
    public Result addDish(@RequestBody DishDTO dishDTO){
        log.info("新增菜品dishDTO:{}",dishDTO);
        dishService.addDish(dishDTO);
        return Result.success();
    }

    /**
     *根据id查询菜品接口  回显
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品接口")
    public Result<DishVO> selectById(@PathVariable Long id){
        DishVO dishVO = dishService.selectById(id);
        return Result.success(dishVO);
    }
    /**
     * 修改菜品接口
     */
    @PutMapping
    @ApiOperation("修改菜品接口")
    public Result updateDish(@RequestBody DishDTO dishDTO){
        dishService.updateDish(dishDTO);
        return Result.success();
    }

    /**
     * 批量删除菜品接口
     */
    @DeleteMapping
    @ApiOperation("批量删除菜品接口")
    public Result deleteBatchDish(@RequestParam("ids") List<Long> ids){
        log.info("批量删除菜品 ids:{}",ids);
        dishService.deleteBatchDish(ids);
        return Result.success();
    }
    /**
     * 启售停售接口
     */
    @PostMapping("/status/{status}")
    @ApiOperation("启售停售接口")
    public Result startOrStopDish(@PathVariable Integer status,Long id){
        log.info("启售停售 status:{},id:{}",status,id);
        dishService.startOrStopDish(status,id);
        return Result.success();
    }
    /**
     * 根据分类id查询菜品接口
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品接口")
    public Result<List<DishVO>> getByCategoryId(Long categoryId){
        Dish dish = Dish.builder().categoryId(categoryId).build();
        List<DishVO> list = dishService.listWithFlavor(dish);
        return Result.success(list);
    }


}
